$(function () {
    initPage();
    function initPage() {
        let Pr_itemInfo = new Promise((resolve,reject)=>{
            $.ajax({
                url: '/manage/projectDetails/details_productt.do',
                data : getSearchInfo(),
                xhrFields : {
                    withCredentials: true
                },
                crossDomain: true,
                success : function (data) {
                    if(data.status == 0){
                        resolve(data);
                    }else if(data.status == 10 ){
                        reject(data);
                    }
                }
            })
        });
        Pr_itemInfo.then((data)=>{
            console.log(data);
            let info = data.data;
            $('#itemTitle').text(info.projectname);// 标题
            $('#itemTeam').text(info.team);// 团队
            $('#itemGrade').text(info.projectgrade);// 等级
            $('#addStus').text(info.addprojectstuname);// 学生
            $('#addTer').text(info.instructor);//老师
            $('#ItemPrize').text(info.getprize);//获奖
            $('#itemInfo').html(info.projectdetailed);// 信息
            $('#itemID').text( getSearchInfo().projectno );// title ID
            $('#itemImgCou').attr('src',info.coverurl);
            let aFilesName = info.evidenceid.split('|');
            let aFilesUrl = info.evidenceurl.split('|');
            $('#filesBox').html('');

            aFilesName.forEach((item,idx)=>{
                if(item !== ''){
                    let DOM = $('<a href="'+ aFilesUrl[idx] +'">' +
                        '   <span>'+ item +'</span>' +
                        '   <i class="glyphicon glyphicon-download-alt"></i>' +
                        '</a>');
                    $('#filesBox').append(DOM);
                }
            });
            if( $('#filesBox').children().length == 0 ){
                $('#filesBox').append($('<span>暂无附件</span>'))
            }

            $('#reviewGroup').find('label').eq(info.examinestatus).addClass( 'btn-primary' ).siblings().removeClass('btn-primary');
            $('#reviewGroup').find('label').eq(info.examinestatus).find('input').prop('checked','true');
            $('#itemPInfen').val(info.reviewnotes);
            $('#textareaBox').val(info.examineresult);
        }).catch((data)=>{
            if(data.status==10){
                spop_waring( data.msg , function() {}, outLogin );
            }
        });
    }

    // 审批状态css切换
    $('.boxAbtns').find('label').on('click',function () {
        $(this).addClass( 'btn-primary' ).siblings().removeClass('btn-primary');
    });

    // 文本框字
    $('#textareaBox').on('input propertychange',function (ev) {
        let size = $(this).val().length;
        if( size > 499 ){
            $(this).val( $(this).val().substring(0,500) );
            size =  $(this).val().length;
        }
        $('#thisSize').text( size );
    });

    // 提交审核
    $('#subItemInfo').on('click',function () {
        if( 0 >= parseInt($('#itemPInfen').val()) || parseInt($('#itemPInfen').val()) > 100){
            spop_waring('评分输入错误');
            return false;
        }
        $.ajax({
            url: '/manage/projectdetailsraceTypesamsara/examine.do',
            type : 'post',
            data : {
                projectnoList : [getSearchInfo().projectno],
                reviewnotes : $('#itemPInfen').val(),
                examinestatus : $("input[name='statusBoxA']:checked").val(),
                examineResult : $('#textareaBox').val(),
            },
            xhrFields : {
                withCredentials: true
            },
            crossDomain: true,
            success : function (data) {
                console.log(data);
                if( data.status == 0 ){
                    spop_ok( data.status,function () {}, history.back() );
                }else if(data.status == 10 ){
                    spop_waring( data.msg,function () {}, outLogin() );
                }else{
                    spop_er( data.msg );
                }
            }
        })
    });
});